
// 1、
// const events =require("events")

// // 创建事件对象
// let myEmitter=new events.EventEmitter()

// // 设置事件监听器
// myEmitter.on("someEvent",function (mes){
//     console.log(mes,"触发了");
// })

// // 触发事件
// myEmitter.emit("someEvent","事件")



// 2、
let events=require('events')
let util=require("util")

let Person=function(name){
    this.name=name
}

// 最关键
// Person继承events.EventEmitter，Person就具有了事件对象，进行new
util.inherits(Person,events.EventEmitter)

let xiaoming=new Person("xiaoming")
let LiLei=new Person("Lilei")

let persons=[xiaoming,LiLei]
persons.forEach(item=>{
    item.on('speak',function(mes){
        console.log(item.name +mes);
        
    })
})
xiaoming.emit("speak",'哈哈')
LiLei.emit("speak","呼呼")
